import pymysql
import openpyxl

db = pymysql.connect(host='10.0.0.133',
                     port=3306,
                     user='root',
                     password='123456',
                     database='text1',
                     charset='utf8')
wb = openpyxl.load_workbook('1.xlsx')
excel_sheet = wb.active
sheet = wb['Sheet1']

#创建游标
# 使⽤ cursor() ⽅法创建⼀个游标对象 cursor
cursor = db.cursor()
# 使⽤ execute() ⽅法执⾏ SQL 查询
sql = ("insert into person (username,age,sex,high) values (%s,%s,%s,%s)")
params = []
for row in sheet.iter_rows(2,11):
    username = row[0].value
    age = row[1].value
    sex = row[2].value
    high = row[3].value
    params.append((username, age, sex, high))
cursor.executemany(sql, params)

# 提交
db.commit()

# 6.关闭资源
cursor.close()
db.close()




